package com.sanjiahantang.youjiarole.module.cases.models.impl;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.BaseBean;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.cases.beans.CaseBean;
import com.sanjiahantang.youjiarole.module.cases.beans.DesignerBean;
import com.sanjiahantang.youjiarole.module.cases.models.ICaseModel;
import com.sanjiahantang.youjiarole.module.cases.views.CaseView;
import com.sanjiahantang.youjiarole.module.common.beans.ConditionBean;
import com.sanjiahantang.youjiarole.module.common.beans.StringBean;
import com.sanjiahantang.youjiarole.module.common.beans.StringCheckBean;
import com.squareup.okhttp.Request;

import java.util.Map;


/**
 * Created by zy on 2017/9/5.
 */

public class CaseModel implements ICaseModel {
    //我的收藏案例查询
    @Override
    public void loadFavoriteCase(final Context context, Map<String, Object> param, final CallBack<CaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/role/searchCollectForCaseInfo", param, new BaseDelegate.ResultCallback<CaseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CaseBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void loadSelectors(final Context context, Map<String, String> params, final CallBack<ConditionBean> callBack, Object tag) {

        String interfaceInfo = ((int) tag == CaseView.TYPE_ADDRESS) ? "/case/phone/role/findCaseAddress" : "/system/dic/findDicByParentForPhone";


        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + interfaceInfo, params, new BaseDelegate.ResultCallback<ConditionBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ConditionBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        }, tag);
    }

    @Override
    public void loadCaseByCondition(final Context context, Map<String, Object> params, final CallBack<CaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/case/phone/role/searchCaseInfo", params, new BaseDelegate.ResultCallback<CaseBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CaseBean response, Object tag) {
                callBack.onSuccess(response, context, null);
            }
        });
    }

    @Override
    public void loadCaseById(final Context context, Map<String, String> param, final CallBack<CaseBean.DetailBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/case/phone/role/findCaseInfo", param, new BaseDelegate.ResultCallback<CaseBean.DetailBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CaseBean.DetailBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void loadDesignerInfo(final Context context, Map<String, String> param, final CallBack<DesignerBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/role/findDesignInfo", param, new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void addCollectInfo(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/role/addCollectInfo", param, new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void deleteCollectInfo(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/role/deleteCollectInfo", param, new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void checkOrderIsCommit(final Context context, Map<String, String> param, final CallBack<StringBean> callBack) {

        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/project/price/phone/role/findIsPlaceAnOrder", param, new BaseDelegate.ResultCallback<StringBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }
}
